package com.hotelsystem.reservations.clientvalidation;

import java.util.Date;

import com.hotelsystem.reservations.reservations.Reservation;

/**
 * Validates the reservation object properties
 * 
 * @author vanjiii
 */
public class ReservationValidator {

	private ClientValidation cv = new ClientValidation();

	public ReservationValidator() {
	}

	/**
	 * Validate the start date of a reservation. It has to be in a proper
	 * format, and to be future date.
	 * 
	 * @param startDate
	 *            the date that has to be checked
	 * @return boolean
	 * 
	 * @author vanjiii
	 */
	public boolean validateStartDate(Date startDate) {
		return startDate.getTime() >= System.currentTimeMillis();
	}

	public boolean isStartDateBeforeEnd(Date startDate, Date endDate) {
		return startDate.before(endDate);
	}

	public String validateReservation(Reservation reservation) {
		StringBuilder errorMessage = new StringBuilder();
		String startDate = cv.validateString("Start date mustn't be in the past\n",
				validateStartDate(reservation.getStartDate()));
		String endDate = cv.validateString("End date must be after start date\n",
				isStartDateBeforeEnd(reservation.getStartDate(), reservation.getEndDate()));
		String client = cv.validateString("Reservatiom must have client\n", reservation.getClient() != null);
		String room = cv.validateString("Reservatiom must have room\n", reservation.getRoom() != null);

		errorMessage.append(startDate);
		errorMessage.append(endDate);
		errorMessage.append(client);
		errorMessage.append(room);

		return errorMessage.toString().trim();
	}
}
